require "RadioMenu"
require "JLZMLayer"
require "JLSLLayer"
require "JLRMLayer"
require "JLPYLayer"
require "JLAllLayer"
require "JLSJLayer"
require "JLSJBuyPointLayer"

JunXiaoScene={}
JunXiaoSceneFunc={}
JunXiaoSceneFunc.__index = JunXiaoSceneFunc
setmetatable(JunXiaoScene, JunXiaoSceneFunc)
JunXiaoScene.NodeID = {Menu=1001}

local JunXiaoSceneID = {Menu=1001}
JunXiaoScene.menuSelected = -1 
JunXiaoScene.menu = nil
JunXiaoScene.contentLayer = nil
JunXiaoScene.guide1 = true 

JunXiaoSceneFunc.getNode = function()
  local l = {}
  setmetatable(l, JunXiaoSceneFunc)
  l.node = CCBReader:load("JunXiaoScene.ccbi")
  print("JunXiaoScene.getNode", JunXiaoScene.node)
  JunXiaoScene.instance = l
  l:init() 
  return l 
end

JunXiaoSceneFunc.getScene = function()
  local sc = CCScene:create()
  sc:addChild(JunXiaoScene:getNode().node)  
  print("JunXiaoScene.getScene", sc)
  return sc
end

JunXiaoSceneFunc.init = function(self)
  setObjectExtTable(self.node:getChildByTag(1111), self)
  self.menu = self.node:getChildByTag(JunXiaoScene.NodeID.Menu)
  self.radioMenu = RadioMenu:create(self.menu, "menuItemChanged", self)
  self.radioMenu:setMenuState(0)
  --self.contentLayer = JLZMLayer:getNode().node
  --self.node:addChild(self.contentLayer) 
  if JunXiaoScene.guide1==true then
    JunXiaoGuide.nextStep()
  end
end

JunXiaoSceneFunc.menuItemChanged = function(self, oldIndex, newIndex)
  print("JunXiaoSceneFunc.menuItemChanged", oldIndex, newIndex)
  if self.contentLayer~=nil then
    print("JunXiaoSceneFunc.menuItemChanged remove")
    self.node:removeChild(self.contentLayer, true)
  end
  if JLSLLayer.instance~=nil then
    JLSLLayer.instance:clearUITimers()
  end
  local cl = nil
  if newIndex==0 then
    cl = JLSLLayer:getNode().node
  elseif newIndex==1 then
    cl = JLZMLayer:getNode().node
  elseif newIndex==2 then
    cl = JLRMLayer:getNode().node 
  elseif newIndex==3 then
    cl = JLAllLayer:getNode().node 
  end
  if cl~=nil then
    self.contentLayer = cl 
    self.node:addChild(self.contentLayer) 
  end
  if JunXiaoScene.guide1==true and newIndex==1 then
    JunXiaoGuide.nextStep()
  end
end

JunXiaoSceneFunc.onClose = function(self, node, event)
  node:getParent():getParent():removeChild(node:getParent(), true)
  setTouchEnabledAll(MainScene.node, true)
  MainScene.setState()
  if JLSLLayer.instance~=nil then
    JLSLLayer.instance:clearUITimers()
  end
  JunXiaoScene.instance = nil
  JLSLLayer.instance = nil
  JLZMLayer.instance = nil
  JLRMLayer.instance = nil
  JunXiaoGuide.state = -1
end
